home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LT_Rebuild.c < prev    next >
C/C++ Source or Header  |  1996-08-22  |  7KB  |  342 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14.  
  15. /*****************************************************************************/
  16.  
  17.  
  18. VOID
  19. LTP_Erase(LayoutHandle *Handle)
  20. {
  21.     struct Window *Window = Handle->Window;
  22.  
  23.     EraseRect(&Handle->RPort,Window->BorderLeft,Window->BorderTop,Window->Width - (Window->BorderRight + 1),Window->Height - (Window->BorderBottom + 1));
  24. }
  25.  
  26.  
  27. /*****************************************************************************/
  28.  
  29.  
  30. /****** gtlayout.library/LT_RebuildTagList ******************************************
  31. *
  32. *   NAME
  33. *    LT_RebuildTagList -- Rebuild the user interface after modifying it.
  34. *
  35. *   SYNOPSIS
  36. *    Success = LT_RebuildTagList(Handle,Clear,TagList);
  37. *       D0                         A0    D0     A1
  38. *
  39. *    BOOL LT_RebuildTagList(LayoutHandle *,BOOL,struct TagItem *);
  40. *
  41. *    Success = LT_RebuildTags(Handle,Clear,...);
  42. *
  43. *    BOOL LT_RebuildTags(LayoutHandle *,BOOL,...);
  44. *
  45. *   FUNCTION
  46. *    Certain aspects of the user interface can be changed at run time,
  47. *    such as button labels. This routine will let you rebuild the interface
  48. *    based upon the data supplied at creation time and your subsequent
  49. *    changes. Before you make any vital changes, it is recommended to
  50. *    lock the window using LT_LockWindow() in order to avoid clashes
  51. *    with the Intuition and GadTools subsystems.
  52. *
  53. *   INPUTS
  54. *    Handle - Pointer to LayoutHandle structure.
  55. *
  56. *    Clear - Pass in TRUE if you wish to have the window contents
  57. *        cleared before they are rebuild. This will introduce
  58. *        some visual hashing.
  59. *
  60. *    TagList - Attributes controlling the layout process.
  61. *
  62. *
  63. *    Valid tags include:
  64. *
  65. *    LAWN_Bounds (struct IBox *) - Boundaries in which the window
  66. *        should be centered.
  67. *
  68. *    LAWN_ExtraWidth (LONG) - Extra space to add to the window
  69. *        width.
  70. *
  71. *    LAWN_ExtraHeight (LONG) - Extra height to add to the window
  72. *        height.
  73. *
  74. *   RESULT
  75. *    Success - TRUE indicates that the interface was rebuilt,
  76. *        FALSE indicates trouble; it is recommended to
  77. *        call LT_DeleteHandle() on your LayoutHandle as
  78. *        soon as possible as the previous operation may
  79. *        have left the user interface in an inoperable
  80. *        state.
  81. *
  82. ******************************************************************************
  83. *
  84. */
  85.  
  86. BOOL LIBENT
  87. LT_RebuildTagList(REG(a0) LayoutHandle *handle,REG(d0) BOOL clear,REG(a1) struct TagItem *TagParams)
  88. {
  89.     struct TagItem    *item,
  90.                     *list;
  91.     struct IBox        *bounds = NULL;
  92.     LONG             RightEdge,
  93.                      BottomEdge;
  94.  
  95.     list = TagParams;
  96.  
  97.     while(item = NextTagItem(&list))
  98.     {
  99.         switch(item->ti_Tag)
  100.         {
  101.             case LAWN_Bounds:
  102.  
  103.                 bounds = (struct IBox *)item->ti_Data;
  104.                 break;
  105.         }
  106.     }
  107.  
  108.     if(handle)
  109.     {
  110.         struct Gadget    *gadget,
  111.                         *next;
  112.         ObjectNode        *node;
  113.         LONG             left,top;
  114.         struct IBox         newBounds;
  115.         struct Image    **ImagePtr;
  116.  
  117.         if(!handle->SizeVerified)
  118.         {
  119.             LTP_StripGadgets(handle,handle->List);
  120. #ifdef DO_BOOPSI_KIND
  121.             LTP_StripGadgets(handle,(struct Gadget *)handle->BOOPSIList);
  122. #endif    /* DO_BOOPSI_KIND */
  123.         }
  124.         gadget = handle->List;
  125.  
  126.         while(gadget)
  127.         {
  128.             if(GETOBJECT(gadget,node))
  129.             {
  130.                 LTP_PutStorage(node);
  131.  
  132.                 ImagePtr = NULL;
  133.  
  134.                 switch(node->Type)
  135.                 {
  136. #ifdef DO_GAUGE_KIND
  137.                     case GAUGE_KIND:
  138.  
  139.                         node->Special.Gauge.LastPercentage = -1;
  140.                         break;
  141. #endif    /* DO_GAUGE_KIND */
  142.  
  143.                     case BUTTON_KIND:
  144.  
  145.                         ImagePtr = &node->Special.Button.ButtonImage;
  146.                         break;
  147.  
  148.                     case PICKER_KIND:
  149.  
  150.                         ImagePtr = &node->Special.Picker.Image;
  151.                         break;
  152.  
  153.                     case TAPEDECK_KIND:
  154.  
  155.                         ImagePtr = &node->Special.TapeDeck.ButtonImage;
  156.                         break;
  157.  
  158.                     case INCREMENTER_KIND:
  159.  
  160.                         ImagePtr = &node->Special.Incrementer.Image;
  161.                         break;
  162.  
  163.                     case STRING_KIND:
  164.  
  165.                         if(!node->Special.String.Backup)
  166.                             node->Special.String.Backup = (STRPTR)LTP_Alloc(handle,node->Special.String.MaxChars + 1);
  167.  
  168.                         if(node->Special.String.Backup)
  169.                         {
  170.                             strcpy(node->Special.String.Backup,((struct StringInfo *)gadget->SpecialInfo)->Buffer);
  171.  
  172.                             node->Special.String.String = node->Special.String.Backup;
  173.                         }
  174.  
  175.                         node->Special.String.Picker = NULL;
  176.  
  177.                         break;
  178.  
  179.                     case TEXT_KIND:
  180.  
  181.                         node->Special.Text.Picker = NULL;
  182.                         break;
  183.  
  184.                     case INTEGER_KIND:
  185.  
  186.                         node->Special.Integer.LeftIncrementer    = NULL;
  187.                         node->Special.Integer.RightIncrementer    = NULL;
  188.  
  189.                         break;
  190. #ifdef DO_LEVEL_KIND
  191.                     case LEVEL_KIND:
  192.  
  193.                         ImagePtr = &node->Special.Level.LevelImage;
  194.                         break;
  195. #endif    /* DO_LEVEL_KIND */
  196.                 }
  197.  
  198.                 if(ImagePtr)
  199.                 {
  200.                     DisposeObject(*ImagePtr);
  201.  
  202.                     *ImagePtr = NULL;
  203.                 }
  204.  
  205.                 node->Host = NULL;
  206.             }
  207.  
  208.             gadget = gadget->NextGadget;
  209.         }
  210.  
  211.         FreeGadgets(handle->List);
  212.  
  213.         handle->List = NULL;
  214.  
  215. #ifdef DO_BOOPSI_KIND
  216.         gadget = (struct Gadget *)handle->BOOPSIList;
  217.  
  218.         while(gadget)
  219.         {
  220.             next = gadget->NextGadget;
  221.  
  222.             if(GETOBJECT(gadget,node))
  223.             {
  224.                 DisposeObject(gadget);
  225.  
  226.                 if(node->Type == BOOPSI_KIND)
  227.                 {
  228.                     if(node->Special.BOOPSI.ClassBase)
  229.                     {
  230.                         CloseLibrary(node->Special.BOOPSI.ClassBase);
  231.  
  232.                         node->Special.BOOPSI.ClassBase = NULL;
  233.                     }
  234.                 }
  235.  
  236.                 node->Host = NULL;
  237.             }
  238.  
  239.             gadget = next;
  240.         }
  241.  
  242.         handle->BOOPSIList = NULL;
  243.         handle->BOOPSIPrevious = NULL;
  244. #endif    /* DO_BOOPSI_KIND */
  245.  
  246.         LTP_Free(handle,handle->GadgetArray,sizeof(struct Gadget *) * handle->Count);
  247.  
  248.         handle->GadgetArray = NULL;
  249.  
  250.         handle->Count = handle->Index = 0;
  251.  
  252.         LTP_ResetGroups(handle->TopGroup);
  253.  
  254.         if(!bounds)
  255.         {
  256.             bounds = &newBounds;
  257.  
  258.             newBounds.Left        = 0;
  259.             newBounds.Top        = 0;
  260.             newBounds.Width        = handle->Window->Width;
  261.             newBounds.Height    = handle->Window->Height;
  262.         }
  263.  
  264.         left        = handle->Window->BorderLeft;
  265.         top            = handle->Window->BorderTop;
  266.         RightEdge    = handle->Window->BorderRight;
  267.         BottomEdge    = handle->Window->BorderBottom;
  268.  
  269.         if(!handle->FlushLeft)
  270.         {
  271.             left        += handle->InterWidth;
  272.             RightEdge    += handle->InterWidth;
  273.         }
  274.  
  275.         if(!handle->FlushTop)
  276.         {
  277.             top            += handle->InterHeight;
  278.             BottomEdge    += handle->InterHeight;
  279.         }
  280.  
  281.         LTP_CreateGadgets(handle,bounds,left,top,left + RightEdge,top + BottomEdge);
  282.  
  283.         if(handle->Failed)
  284.         {
  285.             handle->SizeVerified = FALSE;
  286.  
  287.             LTP_Erase(handle);
  288.  
  289.             RefreshWindowFrame(handle->Window);
  290.  
  291.             return(FALSE);
  292.         }
  293.  
  294.         if(clear)
  295.         {
  296.             LTP_Erase(handle);
  297.  
  298.             if(!handle->SizeVerified)
  299.                 RefreshWindowFrame(handle->Window);
  300.         }
  301.  
  302.         handle->SizeVerified = FALSE;
  303.  
  304.         LTP_AddGadgets(handle);
  305.  
  306.         LTP_SelectInitialActiveGadget(handle);
  307.  
  308.         return(TRUE);
  309.     }
  310.     else
  311.         return(FALSE);
  312. }
  313.  
  314.  
  315. /*****************************************************************************/
  316.  
  317.  
  318. BOOL
  319. LT_RebuildTags(LayoutHandle *Handle,BOOL Clear,...)
  320. {
  321.     va_list VarArgs;
  322.     BOOL    Result;
  323.  
  324.     va_start(VarArgs,Clear);
  325.     Result = LT_RebuildTagList(Handle,Clear,(struct TagItem *)VarArgs);
  326.     va_end(VarArgs);
  327.  
  328.     return(Result);
  329. }
  330.  
  331.  
  332. /*****************************************************************************/
  333.  
  334.  
  335. BOOL LIBENT
  336. LT_Rebuild(REG(a0) LayoutHandle *handle,REG(a1) struct IBox *bounds,REG(a2) LONG extraWidth,REG(d0) LONG extraHeight,REG(d1) BOOL clear)
  337. {
  338.     return(LT_RebuildTags(handle,clear,
  339.         LAWN_Bounds,bounds,
  340.     TAG_DONE));
  341. }
  342.